home *** CD-ROM | disk | FTP | other *** search
- <HTML>
- <HEAD>
- <TITLE>CFOBJECT (COM) Example</TITLE>
- </HEAD>
-
- <BASEFONT FACE="Arial, Helvetica" SIZE=2>
- <BODY bgcolor="#FFFFD5">
-
- <H3>CFOBJECT (COM) Example</H3>
- <!---
- Create a COM object as an inproc server (DLL).
- (CLASS= prog-id). Uses DocEx1.DLL, which may need
- to be registered on the CF Server machine.
- --->
- <!--- Check for platform. COM doesn't run under UNIX. --->
- <CFIF Server.OS.Name EQ "Windows NT">
- <CFOBJECT TYPE="COM"
- ACTION="Create"
- CLASS="Allaire.DocEx1.1"
- NAME="obj">
-
- <!---
- Call a method.
- Note that methods that expect no arguments should
- be called using empty parenthesis.
- --->
- <CFSET obj.Init()>
-
- <!---
- This object is a collection object, and should
- support at a minimum:
- Property : Count
- Method : Item(inarg, outarg)
- and a special property called _NewEnum
- --->
- <CFOUTPUT>
- This object has #obj.Count# items.
- <BR>
- <HR>
- </CFOUTPUT>
-
-
- <!---
- Get the 3rd object in the collection.
- --->
- <CFSET emp = obj.Item(3)>
- <CFOUTPUT>
- The last name in the third item is #emp.lastname#.
- <BR>
- <HR>
- </CFOUTPUT>
-
- <!---
- Loop over all the objects in the collection.
- --->
- <P>Looping through all items in the collection:
- <BR>
- <CFLOOP COLLECTION=#obj# ITEM=file2>
- <CFOUTPUT>
- Last name: #file2.lastname# <BR>
- </CFOUTPUT>
- </CFLOOP>
-
- <CFELSE>
- <H4>COM supported is limited to the Windows/NT platform.</H4>
- </cfif>
-
- <!-----
- IDL for the object
- **** Important Note ***********************************
- The Item() method takes a VARIANT as an [in] argument. ColdFusion
- cannot determine the type and simply sends a BSTR. IF THE OBJECT
- does not corece it to the right type (which it does in this case)
- using the following :
-
- HRESULT hr;
-
- // Check to see if a number has been passed
- if (Index.vt != VT_I4)
- {
- hr = VariantChangeType(&Index, &Index, 0, VT_I4);
- }
-
- then an error will be reported. To avoid these type of problems,
- object developers should specify the type directly in the IDL.
-
- For example, if the IDL had been coded :
-
- HRESULT Item([in] long index, [out,retval] LPVARIANT pItem);
-
- **** Important Note ***********************************
- import "oaidl.idl";
- import "ocidl.idl";
-
- [
- object,
- uuid(3607722F-3B5A-11D2-BEBB-00C04FA35D22),
- dual,
- helpstring("IEmployeeCollection Interface"),
- pointer_default(unique)
- ]
- interface IEmployeeCollection : IDispatch
- {
- [propget, id(1), helpstring("property Count")]
- HRESULT Count([out, retval] long *pVal);
- [id(2), helpstring("method Item")]
- HRESULT Item([in] VARIANT index, [out,retval] LPVARIANT pItem);
- [id(3), helpstring("method Init")] HRESULT Init();
- [propget, id(-4), helpstring("property _NewEnum"), restricted]
- HRESULT _NewEnum([out, retval] LPUNKNOWN *pVal);
- };
- [
- object,
- uuid(36077231-3B5A-11D2-BEBB-00C04FA35D22),
- dual,
- helpstring("IEmployee Interface"),
- pointer_default(unique)
- ]
- interface IEmployee : IDispatch
- {
- [propget, id(1), helpstring("property EmployeeID")]
- HRESULT EmployeeID([out, retval] long *pVal);
- [propput, id(1), helpstring("property EmployeeID")]
- HRESULT EmployeeID([in] long newVal);
- [propget, id(2), helpstring("property LastName")] HRESULT LastName([out, retval] BSTR *pVal);
- [propput, id(2), helpstring("property LastName")] HRESULT LastName([in] BSTR newVal);
- };
- [
- uuid(36077222-3B5A-11D2-BEBB-00C04FA35D22),
- version(1.0),
- helpstring("DocEx1 1.0 Type Library")
- ]
- library DOCEX1Lib
- {
- importlib("stdole32.tlb");
- importlib("stdole2.tlb");
-
- [
- uuid(36077230-3B5A-11D2-BEBB-00C04FA35D22),
- helpstring("EmployeeCollection Class")
- ]
- coclass EmployeeCollection
- {
- [default] interface IEmployeeCollection;
- };
- [
- uuid(36077232-3B5A-11D2-BEBB-00C04FA35D22),
- helpstring("Employee Class")
- ]
- coclass Employee
- {
- [default] interface IEmployee;
- };
- };
- --->
-
- </BODY>
- </HTML>
-